<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Multi Search Template | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'multi-search-template.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/multi-search-template.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/multi-search-template.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/multi-search-template.html" rel="nofollow" target="_blank">../en/multi-search-template.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="search.html">Search APIs</a></span>
»
<span class="breadcrumb-node">Multi Search Template</span>
</div>
<div class="navheader">
<span class="prev">
<a href="search-template.html">« Search Template</a>
</span>
<span class="next">
<a href="search-shards.html">Search Shards API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="multi-search-template"></a>Multi Search Template<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/search-template.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Allows to execute several search template requests.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="multi-search-template-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/search-template.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">GET _msearch/template</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="multi-search-template-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/search-template.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Allows to execute several search template requests within the same API using the
<code class="literal">_msearch/template</code> endpoint.</p>
<p>The format of the request is similar to the <a class="xref" href="search-multi-search.html" title="Multi Search API">Multi
Search API</a> format:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">header\n
body\n
header\n
body\n</pre>
</div>
<p>The header part supports the same <code class="literal">index</code>, <code class="literal">search_type</code>, <code class="literal">preference</code>, and
<code class="literal">routing</code> options as the Multi Search API.</p>
<p>The body includes a search template body request and supports inline, stored and
file templates.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="multi-search-template-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/search-template.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">$ cat requests
{"index": "test"}
{"source": {"query": {"match":  {"user" : "{{username}}" }}}, "params": {"username": "john"}} <a id="CO626-1"></a><i class="conum" data-value="1"></i>
{"source": {"query": {"{{query_type}}": {"name": "{{name}}" }}}, "params": {"query_type": "match_phrase_prefix", "name": "Smith"}}
{"index": "_all"}
{"id": "template_1", "params": {"query_string": "search for these words" }} <a id="CO626-2"></a><i class="conum" data-value="2"></i>

$ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/template --data-binary "@requests"; echo</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO626-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Inline search template request</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO626-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Search template request based on a stored template</p>
</td>
</tr>
</table>
</div>
<p>The response returns a <code class="literal">responses</code> array, which includes the search template
response for each search template request matching its order in the original
multi search template request. If there was a complete failure for that specific
search template request, an object with <code class="literal">error</code> message will be returned in
place of the actual search response.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="search-template.html">« Search Template</a>
</span>
<span class="next">
<a href="search-shards.html">Search Shards API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>